package cmdServer

import (
	"encoding/base64"
	"fmt"
	"net"
	"os"
	"remote-go/server/data"
	"remote-go/server/util"
)

func SendUpload(ok bool, _conn net.Conn) {
	if ok {
		encUpload := base64.URLEncoding.EncodeToString([]byte("upload"))
		_conn.Write([]byte(encUpload + "\n"))

		workDir, _ := os.Getwd()

		fmt.Printf("File Path to Upload(%s): ", workDir)
		pathUpload := util.ReadLine()
		//上传文件
		file, err := os.ReadFile(pathUpload)
		if err != nil {
			fmt.Println(data.RED, "%s/%s File not found!", workDir, pathUpload)
			return
		}

		fmt.Print("Output name: ")
		outputName := util.ReadLine()
		encOutput := base64.URLEncoding.EncodeToString([]byte(outputName))
		_conn.Write([]byte(encOutput + util.GetDateTime() + "\n"))

		fmt.Println(data.YELLOW, "-> Uploading...")
		encData := base64.URLEncoding.EncodeToString(file)
		_conn.Write([]byte(string(encData) + "\n"))
		fmt.Println(data.GREEN, "-> Upload Done...")
	} else {
		fmt.Println("请重新选择客户端, help查看帮助")
	}
}
